<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<#include "/common/plateform/include/common-base.ftl">
	<title>角色管理</title>
	<!-- Tell the browser to be responsive to screen width -->
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>

<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

	<!-- top start -->
	<#include "/common/plateform/top.ftl">
	<!-- top end -->

	<!-- left start -->
	<#include "/common/plateform/left-project.ftl">
	<!-- left end-->

  <div class="content-wrapper">
    <!-- Main start -->
	<section class="content">
	  			<div id="div_hidden_content" class="hidden" style="display:none;">
	  			    <input name="templateType" type="hidden" value="all"/>
                    <div id="hidden_common_final">
                        <!-- temp="hidden_common_final" start -->
										<input name="mainObjName" type="hidden" value="uctRole">
										<input name="mainObjPrimaryKey" type="hidden" value="roleId">
										<input name="objNameAll" type="hidden" value="uctRole">
				<!-- temp="hidden_common_final" end -->
                     </div>
                    <!-- temp="delForm_hidden" start -->
									<div id="delForm_hidden" style="display:none;">
										<input type="hidden" name="pageName" value="uct-role-list"/>
										<input type="hidden" name="formName" value="delForm"/>
									</div>
				<!-- temp="delForm_hidden" end -->
	  			</div>
      <div class="row">
        <div class="col-xs-12">
        
          <!------搜索  start ------->
          <div class="box box-info">
             <!--搜索title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-search"></i> 角色管理搜索</h3>
                 <div class="box-tools pull-right">
    				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
 				 </div>
              </div>
            <!--搜索title  end --> 
            <div class="box-body">
            	<form id="searchForm" action="javascript:;">
	            	<!-- temp="searchForm_hidden" start -->
									<div id="searchForm_hidden" style="display:none;">
										<input type="hidden" name="pageName" value="uct-role-list"/>
										<input type="hidden" name="formName" value="searchForm"/>
										<input type="hidden" class="input_sysEname" name="uctRole.sysEname" value=""/>
										<input type="hidden" name="orderBy" value="uctRole.create_time desc"/>
									</div>
				<!-- temp="searchForm_hidden" end -->
					
	              	<!-- temp="searchForm_content" start -->
				<div id="searchForm_content" class="form-group"  data-temp-code="true" data-temp-type="searchForm" data-temp-form-id="searchForm">


					<table class="table table-bordered bordercolor"><tbody><tr><td class="active" align="right"><label class="form-control-static">角色标识：</label></td><td><div class="form-group"><input name="uctRole.wl_roleEname" class="form-control clean" maxlength="30" data-temp-obj="uctRole.roleEname"></div></td><td class="active" align="right"><label class="form-control-static">角色名称：</label></td><td><div class="form-group"><input name="uctRole.wl_roleCname" class="form-control clean" maxlength="30" data-temp-obj="uctRole.roleCname"></div></td></tr></tbody></table>
				</div>
				<!-- temp="searchForm_content" end -->
			  	</form>
			  <div class="box-footer text-center">
			       <button type="button" class="btn btn-success" onclick="getTableData();" data-temp-event="searchForm_hidden"><i class="fa fa-search"></i> 查询</button> 
			       <button type="button" class="btn btn-warning" onclick="mytools.cleanData('#searchForm');">重置 </button>
			   </div>
            </div>
	     </div>
	     <!------- 搜索 end -------->
           
        <!------- 列表 start -------->
          <div class="box box-success">
            <!--列表title  start --> 
	          <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-table"></i> 查询结果 
                 　　　              <button id="button_to_add" onclick="toAdd();" class="btn btn-success" type="button"><i class="fa fa-plus-circle"></i> 增加 </button>
                 </h3>
                 <div class="box-tools pull-right">
    				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
 				 </div>
              </div>
			  <div class="box-body">
              	 	<table id="dataList" class="table table-bordered table-hover">
              	 		<thead>
		                	<tr id="dataList_thead_content" data-temp-code="true" data-temp-type="table" data-temp-show="dataList_template_content">
			                	<th>序号</th>
			                	<!-- temp="dataList_thead_content" start -->

											<th data-temp-obj="uctRole.roleEname">角色标识</th>
											<th data-temp-obj="uctRole.roleCname">角色名称</th>
											<th data-temp-obj="uctRole.roleStatus">角色状态</th>
											<th data-temp-obj="uctRole.createTime">创建时间</th>
											<th>操作</th>
				<!-- temp="dataList_thead_content" end -->
		                	</tr>
	                	</thead>
		                <tbody id="dataList-body">
		                	
		                </tbody>
	              </table>
            	</div>
           	 	
           	 	<div class="box-footer text-center">
			      	<ul id="dataList-page" class="pagination">
					</ul>
			 	</div>              
           </div>
        <!------- 列表 end -------->
        </div>
      </div>
  
<div win-title="添加窗口" class="modal fade" id="my_modal_add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:50%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">信息添加</font> 
						</h4>
					</div>

					<div class="modal-body">
						
					       <div class="nav-tabs-custom">
					            <ul class="nav nav-tabs" id="myTab-add">
					            </ul>
					              
					            <!-- tab content start -->
					            <div class="tab-content">
					            
					               <div class="tab-pane active" id="tabAdd_1">
					                  <form class="form-horizontal addFormBody" role="form" id="addForm1" action="javascript:void(0)">
					                    <input type="hidden" class="formToken" id="addForm1_formToken" name="formToken" />
					                    <!-- temp="addForm1_hidden" start -->
									<div id="addForm1_hidden" style="display:none;">
										<input type="hidden" name="pageName" value="uct-role-list"/>
										<input type="hidden" name="formName" value="addForm"/>
										<input type="hidden" name="uctRole.roleStatus" value="1"/>
										<input type="hidden" class="input_sysEname" name="uctRole.sysEname" value=""/>
										<input type="hidden" name="uctRole.delStatus" value="${loginUser.orgId}"/>
										<input type="hidden" name="uctRole.roleRemark" value="${loginUser.orgCname!''}"/>
									</div>
									<!-- temp="addForm1_hidden" end -->
										
					                    <!-- temp="addForm1_content" start -->
											<div id="addForm1_content" data-temp-code="true" data-temp-type="addForm" data-temp-form-id="addForm1">

												<table class="table table-bordered bordercolor">
													<tbody>
													<tr>
														<td class="active" align="right"><label
																class="form-control-static">角色标识：</label></td>
														<td>
															<div class="form-group"><input name="uctRole.roleEname"
																						   class="form-control clean"
																						   maxlength="30"
																						   data-temp-obj="uctRole.roleEname"
																						   placeholder="必填项，只能是数字和字母组成" data-bv-regexp="true" data-bv-regexp-regexp="^[0-9a-zA-Z_]+$" data-bv-regexp-message="只能是数字和字母组成！"
																						   data-bv-notempty="true"
																						   data-bv-notempty-message="不能为空">
															</div>
														</td>
													</tr>
													<tr>
														<td class="active" align="right"><label
																class="form-control-static">角色名称：</label></td>
														<td>
															<div class="form-group"><input name="uctRole.roleCname"
																						   class="form-control clean"
																						   maxlength="30"
																						   data-temp-obj="uctRole.roleCname"
																						   placeholder="必填项"
																						   data-bv-notempty="true"
																						   data-bv-notempty-message="不能为空">
															</div>
														</td>
													</tr>
													</tbody>
												</table>
											</div>
				<!-- temp="addForm1_content" end -->
										
					                    
					                    <div class="form-group">
								        	<div class="col-sm-12">
									         <div class="box-footer text-center">
												<button class="btn btn-success pull-left" type="button" onclick="mytools.closeModal('my_modal_add');"> 取消 </button>
				                				<button class="btn btn-danger pull-right" type="button" onclick="submitForm1('addForm1','');" data-temp-event="addForm1_hidden"> 提 交 </button>
					            			</div>
				            				</div>
				            			</div>
				            			
					                  </form>
					               </div>
					          
				            </div>
					            <!-- tab content e -->
				          </div>	
			                
					</div>
				</div>
				<!-- /.modal-content -->
			</div>		
</div>  

<div win-title="修改窗口" class="modal fade" id="my_modal_edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:50%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">信息修改</font> 
						</h4>
					</div>
					<div class="modal-body">
						 <div class="nav-tabs-custom">
					            <ul class="nav nav-tabs" id="myTab-edit">
					            </ul>
					            
					            <!-- tab content start -->
					            <div class="tab-content">
					            
					               <div class="tab-pane active" id="tabEdit_1">
					                  <form class="form-horizontal editFormBody" role="form" id="editForm1" action="javascript:void(0)">
									    <input type="hidden" class="formToken" id="editForm1_formToken" name="formToken" />
									    <!-- temp="editForm1_hidden" start -->
									<div id="editForm1_hidden" style="display:none;">
										<input type="hidden" name="pageName" value="uct-role-list"/>
										<input type="hidden" name="formName" value="editForm"/>
										<input type="hidden" name="uctRole.w_roleId" data-name="uctRole.roleId" class="uctRole_roleId clean">
									</div>
				<!-- temp="editForm1_hidden" end -->
										
										<!-- temp="editForm1_content" start -->
				<div id="editForm1_content">
					<table class="table table-bordered bordercolor">
						<tbody>
						<tr>
							<td class="active" align="right"><label class="form-control-static">角色标识：</label></td>
							<td>
								<div class="form-group"><input name="uctRole.roleEname" class="form-control clean"
															   maxlength="30" data-temp-obj="uctRole.roleEname"
															   placeholder="必填项" data-bv-notempty="true"
															   data-bv-notempty-message="不能为空" placeholder="必填项，只能是数字和字母组成" data-bv-regexp="true" data-bv-regexp-regexp="^[0-9a-zA-Z_]+$" data-bv-regexp-message="只能是数字和字母组成！"
															   data-name="uctRole.roleEname"></div>
							</td>
						</tr>
						<tr>
							<td class="active" align="right"><label class="form-control-static">角色名称：</label></td>
							<td>
								<div class="form-group"><input name="uctRole.roleCname" class="form-control clean"
															   maxlength="30" data-temp-obj="uctRole.roleCname"
															   placeholder="必填项" data-bv-notempty="true"
															   data-bv-notempty-message="不能为空"
															   data-name="uctRole.roleCname"></div>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				<!-- temp="editForm1_content" end -->
																                    
					                    <div class="form-group">
								        	<div class="col-sm-12">
									         <div class="box-footer text-center">
												<button class="btn btn-success pull-left" type="button" onclick="mytools.closeModal('my_modal_edit');"> 取消 </button>
				                				<button class="btn btn-danger pull-right" type="button" onclick="submitForm1('editForm1','');" data-temp-event="editForm1_hidden"> 提 交 </button>
					            			</div>
				            				</div>
				            			</div>
					                  </form>
					               </div>
					          
				            </div>
					            <!-- tab content e -->
				          </div>	
					</div>
				</div>
				<!-- /.modal-content -->
	</div>		
</div>  

<div win-title="查看窗口" class="modal fade" id="my_modal_view" tabindex="-2" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:50%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							×
						</button>
						<h4 class="modal-title">
							<font color="red">查看详情</font> 
						</h4>
						<form id="viewForm" action="javascript:void(0)">
							<!-- temp="viewForm_hidden" start -->
							<div id="viewForm_hidden" style="display:none;"></div>
							<!-- temp="viewForm_hidden" end -->
						</form>
					</div>
					<div class="modal-body viewForm">
						
						<div class="nav-tabs-custom">
					            <ul class="nav nav-tabs" id="myTab-view">
					            </ul>
					            
					            <!-- tab content start -->
					            <div class="tab-content">
					            
					               <div class="tab-pane active" id="tabView_1">
					                  <form class="form-horizontal" role="form" id="viewForm1" action="javascript:void(0)">
					              		
					              		<!-- temp="viewForm1_content" start -->
				<div id="viewForm1_content" class="row viewForm">
					<table class="table table-bordered bordercolor">
						<tbody>
						<tr>
							<td class="active" align="right"><label class="form-control-static">角色标识：</label></td>
							<td>
								<div class="form-control-static"><span data-name="uctRole.roleEname"></span></div>
							</td>
						</tr>
						<tr>
							<td class="active" align="right"><label class="form-control-static">角色名称：</label></td>
							<td>
								<div class="form-control-static"><span data-name="uctRole.roleCname"></span></div>
							</td>
						</tr>
						<tr>
							<td class="active" align="right"><label class="form-control-static">创建时间：</label></td>
							<td>
								<div class="form-control-static"><span data-name="uctRole.createTime"></span></div>
							</td>
						</tr>
						<tr>
							<td class="active" align="right"><label class="form-control-static">所属机构：</label></td>
							<td>
								<div class="form-control-static"><span data-name="uctRole.roleRemark"></span></div>
							</td>
						</tr>
						</tbody>
					</table>
				</div>
				<!-- temp="viewForm1_content" end -->
					                    
					                  </form>
					                  <div class="form-group">
                                        <div class="col-sm-12">
                                         <div class="box-footer text-center">
                                            <button class="btn btn-success pull-right" type="button" onclick="mytools.closeModal('my_modal_view');"> 关闭 </button>
                                        </div>
                                        </div>
                                      </div>
					               </div>
					               
					          
				            </div>
					            <!-- tab content e -->
				          </div>
					</div>
				</div>
				<!-- /.modal-content -->
	</div>		
</div>

<div win-title="权限窗口" class="modal fade" id="my_modal_act" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width:80%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title"><font color="red">角色权限分配</font>&nbsp;<font id="model_span_title_user_name" class="f14 text-info"></font></h4>
				<div class="lh25 pt5 f12 text-danger">
					<i class="fa fa-info-circle"></i> 操作提示：当子级展开情况下，设置父级的同时可同步批量设置子级！
				</div>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" role="form" id="actForm">
					<input name="userId" id="act-userId" type="hidden">
					<!-- Custom Tabs -->
					<div class="nav-tabs-custom">
						<div class="panel">
							<div class="panel-body">
								<table id="table3" class="table table-bordered table-hover" >
									<thead>
									<tr>
										<th>权限名称</th>
										<th>权限英文全称</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody id="userActList"></tbody>
								</table>
							</div>
						</div>
						<!-- /.tab-content -->
					</div>
					<!-- nav-tabs-custom -->
				</form>
			</div>
		</div>
	</div>
</div>
<!-- Part 二、以下是template模板定义的模块区域 -->
<script type="text/template" id="dataList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
		<tr>
				<td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
			<!-- temp="dataList_template_content" start -->
				<td style='display:none;'><input type="hidden" name="input_primaryKey" obj-name="uctRole" primary="roleId" value="<?=strUtil.doNull(rows[i].uctRole.roleId,'')?>"/></td>
				<td><?=strUtil.doNull(rows[i].uctRole.roleEname,'')?></td>
				<td><?=strUtil.doNull(rows[i].uctRole.roleCname,'')?></td>
				<td>
					<?if(rows[i].uctRole.roleStatus=='1'){?>
					<span class="text-green">启用中</span>
					<?}else{?>
					<span class="text-red">已停用</span>
					<?}?>
				</td>
				<td><?=getFormatDateByLong(rows[i].uctRole.createTime,'yyyy-MM-dd hh:mm:ss')?></td>
				<!-- temp="dataList_template_content" end -->
              <td>
				<button type="button" class="btn btn-primary btn-xs" onclick="toAddAct('<?=rows[i].uctRole.roleId?>','<?=rows[i].uctRole.roleEname?>','<?=rows[i].uctRole.roleCname?>')"><i class="fa fa-cog"></i> 分配权限</button>  
				<button type="button" class="btn btn-warning btn-xs" onclick="toLoad(this,'edit');"><i class="fa fa-edit"></i> 修改</button>  
				<button type="button" class="btn btn-danger btn-xs" onclick="toDele('<?=rows[i].uctRole.roleId?>');"><i class="fa fa-trash-o"></i> 删除</button>
			</td>
		</tr>
   <?}?>  		
</script>
<script type="text/template" id="userActListData">
	<? for ( var i = 0; i < rows.length; i++) {?>
	<tr id="<?=rows[i].uctAct.actId?>"  fatherId="<?=rows[i].uctAct.fatherId?>">
		<?if(rows[i].uctAct.subCount>0||"0"==rows[i].uctAct.fatherId){?>
		<td class="textLeft" id="css_<?=rows[i].uctAct.actId?>" title="当展开子级后可同步批量设置" onclick="getChildActsData('<?=rows[i].uctAct.fatherId?>','<?=rows[i].uctAct.actId?>','<?=rows[i].uctAct.fullEname?>',this);">
			<i class="fa fa-plus" ></i>&nbsp;<?=rows[i].uctAct.actCname?>
		</td>
		<?} else{?>
		<td class="textLeft" id="css_<?=rows[i].uctAct.actId?>">
			&nbsp;<?=rows[i].uctAct.actCname?>
		</td>
		<?}?>
		<td class="textLeft">
			<?=rows[i].uctAct.fullEname?>
		</td>
		<td class="act-tools" <?if(rows[i].uctAct.subCount>0||"0"==rows[i].uctAct.fatherId){?>title="双击图标可设置，当子级展开时也可同步批量设置"<?}?>>
			<i ondblclick="clickGiveRole(this)"
			<?if(myActGiveData[rows[i].uctAct.actId]){?> class="fa fa-check fa-2x" <?}else{?>class="fa fa-close fa-2x"<?}?>
			sub-count="<?=rows[i].uctAct.subCount?>"
			full-ename="<?=rows[i].uctAct.fullEname?>"
			full-cname="<?=rows[i].uctAct.fullCname?>"
			act-id="<?=rows[i].uctAct.actId?>">
			</i>
		</td>
	</tr>
	<?}?>
</script>
<!-- Part 三、 以下是js模块区域 -->
<script>
var clickMenu = "user-role-list";
var myPage,dataListId,searchFormId;
myPage = 10;//定义列表数据
dataListId = "dataList";//显示列表数据div的id
searchFormId = "searchForm";//搜索表单Id
var defSysEname = strUtil.doNull(strUtil.getLocalStorage("sysEname"), "");
$(".input_sysEname").val(defSysEname);
var thisSysEnameFirstActId='', select_roleId = '',select_roleEname='';
var myActGiveData = {};
/**
 * 初始化数据字典，id传入#id 返回值Map用法：dictListMap["userType"][rows[i].userType]
 */
var dictListMap = DictUtil.initDictAndDymic();
 
$(function () {
	//1、加载分页列表数据
	getTableData();

	//2、控制是否启用token
	//setToken();
	
 });
 
 $(function () {
	//设置数据行选中效果
	$('#'+dataListId+' tbody').on('click','tr', function (e) {
	     if ( $(this).hasClass('selected') ) {
	        }
	        else {
	            $('tr.selected').removeClass('selected');
	            $(this).addClass('selected');
	        }
	     //var id = $('tr.selected th').eq(0).html();
	} );
 });
//注入日历框样式
var dateObject = $('.datepicker').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
	autoclose: true
}).on('hide',function(e) {
	//bootstrap datepicker与bootstrapValidator同时使用时选择日期后无法正常触发校验的解决方法
	//当日期选择框关闭时，执行刷新校验。
	var fieldName = $(this).attr("name");//获取当前元素name
	var formId = $(this).parents("form").eq(0).attr("id");//获取当前元素所在父层级中的就近的formId
    $("#"+formId).data('bootstrapValidator').updateStatus(fieldName,'NOT_VALIDATED',null).validateField(fieldName);
});

//给模态窗口内form表单内的所有支持必填项的元素注入校验
$(".modal").on('shown.bs.modal', function () {
	$(this).find("form").each(function(){
		var formId = $(this).attr("id");
		if(!strUtil.isNull(formId)){
			formId="#"+formId;
		 	setValidate(formId);//定义add表单验证属性
			mytools.cleanValidate(formId);//清空上次校验规则提示
		}
	});
});

//打开添加modal
function toAdd(){
	mytools.cleanData(".addFormBody");//清空表单元素上次填写的内容；
	$(".datepicker").val("");
	$("#my_modal_add").modal("show");
}
//数据toLoad读取（查看、编辑）数据
function toLoad(obj,type){
	if("view"==type){
		$("#my_modal_view").modal("show");
	}else if("edit"==type){
		mytools.cleanData(".editFormBody");//清空表单元素上次填写的内容；
		$("#my_modal_edit").modal("show");
	}
	var paramLoadData = {};
	var inputPrimaryObj = $(obj).parent().parent().find("input[name='input_primaryKey']");
	paramLoadData["pageName"]=$("#searchForm").find("input[name='pageName']").val();
	paramLoadData["formName"]=$("#searchForm").find("input[name='formName']").val();
	if(inputPrimaryObj.length>0){
        for(var k=0;k<inputPrimaryObj.length;k++){
            var pkobj=$(inputPrimaryObj[k]);
            paramLoadData[pkobj.attr("obj-name")+".w_"+pkobj.attr("primary")]=pkobj.val();
        }
		$.get(common_info_url, paramLoadData,function(myData){
			console.log(myData);
			//反显加载数据
			if(myData){
				for(var objNameKey in myData){
					FormUtil.loadView(objNameKey, myData[objNameKey],"#my_modal_"+type);
				}
			}
	   	},"json");
	}
}
//删除调用
function toDele(roleId){
	getMyActGiveData(roleId);
	if(!$("#delForm_hidden").find("input[name='formName']").val()){
		layer.alert("缺失删除参数！");
		return;
	}
	if(Object.keys(myActGiveData).length>0){
		layer.alert("该角色已分配了权限，暂时不能删除！");
		return;
	}
	var index_submit = layer.confirm("您确定要删除信息吗？", {btn: ["Yes","No"],closeBtn: 0,offset: "220px"}
	, function(){
		layer.close(index_submit);
		var paramData = {};
		paramData["pageName"]=$("#delForm_hidden").find("input[name='pageName']").val();
		paramData["formName"]=$("#delForm_hidden").find("input[name='formName']").val();
		paramData["uctRole.w_roleId"]=roleId;
		$.ajax({
			type:"post",
			url:common_submit_url,
			data: paramData,dataType:"json",
			success: function(myData){
				var result = myData.flag;
				if(result=="T"){
					refresh();
				}else{
					layer.alert("删除失败！");
				}
			}
		});
	});
}
//加载列表数据
function getTableData(){
    if(strUtil.isNull($("#"+searchFormId).find("input[name='pageName']").val())){return;}
    var index_load = layer.load(1, {shade: false});
	$.ajax({
		   type:'get',
		   url:common_list_url,
		   data:$("#"+searchFormId).serialize()+getCurrentPage(common_list_url+"?"+$("#"+searchFormId).serialize(),myPage),
		   dataType:'json',
		   success: function(myData){
		   	console.log(myData);
		   	if("T"==myData.flag){
			    var data = baidu.template(dataListId+"-template",eval(myData));
				$("#"+dataListId+"-body").html(data);
				  var option= {
						   ele:$("#"+dataListId+"-page")[0],
						   total:myData.total,
						   fn:getTableData,
						   url:common_list_url+"?"+$("#"+searchFormId).serialize()
					   }
					generatePages(option);

			   }
		    layer.close(index_load);
		   }
		});
  }

//初始化权限根目录（权限）
function initActBySysEname() {
	$.ajax({type:'get',
		url:common_info_url,
		data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_sysEname':defSysEname,'uctAct.w_fatherId':'0'},
		dataType:'json',
		success: function(myData){
			if(myData){
				thisSysEnameFirstActId=myData['uctAct'].actId;
				console.log('thisSysEnameFirstActId-->',thisSysEnameFirstActId);
			}
		}
	});
}
//打开权限modal
function toAddAct(roleId,roleEname,roleCname){
	$("#model_span_title_user_name").text(" [被授权角色："+roleCname+"]");
	select_roleId=roleId;
	select_roleEname = roleEname;
	getActListData();
	$("#my_modal_act").modal("show");
}

//加载定义的该系统所有权限数据
function getActListData(){
	$("#userActList").html("");
	var index_load = layer.load(1, {shade: false});
	getMyActGiveData(select_roleId);
	console.log("myActGiveDataMap",myActGiveData);
	$.ajax({type:'get',
		url:common_list_url,
		data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_sysEname':defSysEname,'uctAct.w_fatherId':'0'},
		dataType:'json',
		success: function(myData){
			console.log("uct-act-myData",myData);
			if(myData.total>0){
				layer.close(index_load);
				var data = baidu.template('userActListData',eval(myData));
				$("#userActList").html(data);
			}
		}
	});
}
//查询当前角色已选中权限
function getMyActGiveData(id){
	myActGiveData={};
	var index_load = layer.load(1, {shade: false});
	$.ajax({type:'get',
		url:common_list_url,async: false,
		data:{'pageName':'uct-act-give-list','formName':'searchForm','uctActGive.w_sysEname':defSysEname,'uctActGive.w_giveType':'role','uctActGive.w_roleId':id},
		dataType:'json',
		success: function(myData){
			console.log("myActGiveData",myData);
			layer.close(index_load);
			if(myData.flag=='T'&& myData.total>0){
				for(var i=0;i<myData.rows.length;i++){
					var giveObj = myData.rows[i].uctActGive;
					var key = giveObj.actId;
					var val = giveObj.actFullEname;
					myActGiveData[key]=val;
				}
			}
		}
	});
}
function getChildActsData(fatherId,actId,treeLevel,obj){
	// alert(fatherId+"------"+actId+"------"+treeLevel+"------"+obj)
	var count =0;
	var ss = treeLevel.split("/");
	count = ss.length-1;
	$.ajax({ type:'get',url:common_list_url,
		data:{'pageName':'uct-act-list','formName':'searchForm','uctAct.w_fatherId':actId,'uctAct.w_sysEname':defSysEname,'orderBy':'uctAct.order_num'},
		dataType:'json',
		success: function(myData){
			console.log(myData);
			var data = baidu.template('userActListData',myData);
			if($(obj).find("i").hasClass("fa-minus")){
				$(obj).find("i").attr("class","fa fa-plus");
				delActsChiled(actId);
			}else{
				$(obj).find("i").attr("class","fa fa-minus");
				$("#"+actId).after(data);
				$("[fatherid='"+actId+"']").each(function(i){
					var thisObj = $(this);
					var pd = "10px 20px 10px ";
					var num = pd+(count*20)+"px";
					$(thisObj).find("td").eq(0).css("padding",num);
				});
			}
		}
	});
}
function delActsChiled(id){
	$("[fatherid='"+id+"']").each(function(i){
		var thisObj = $(this);
		$(thisObj).remove();
		var id = thisObj.attr("id");
		delActsChiled(id);
	});
}
//新增或者删除权限数据公用方法
function addUpdateActGive(isAdd,actId,fullEname) {
	var result = false;
	if(strUtil.isNull(actId) || strUtil.isNull(fullEname)){
		return result;
	}
	var index_load = layer.load(1, {shade: false});
	var flag = "add";
	if(isAdd){
		flag = "add";
	}else{
		flag = "del";
	}
	$.ajax({type: "post",async: false,
		url: ctx+"/res/uct/admin/authorizeAct?actGiveType=role&flag="+flag+"&id="+actId+"&objId="+select_roleId,
		success: function(resultData){
			console.log(flag+"->"+select_roleEname,actId+"->"+fullEname,resultData);
			var myData = JSON.parse(resultData);
			layer.close(index_load);
			if(myData.flag=="T"){
				result = true;
			}else{
				console.log("uctActGive",myData);
				layer.msg("授权操作操作失败，请重新尝试！");
			}
		}
	});
	return result;
}
//点击授权
function clickGiveRole(ob) {
	var result = false;
	var obj = $(ob);
	var userActListObjBody = $("#userActList");
	var thisActId = obj.attr("act-id");
	var thisfullEname=obj.attr("full-ename");
	var thisSubCount = obj.attr("sub-count");
	var thisFatherId = obj.parent().parent().attr("fatherid");
	var isAdd = false;
	if(obj.hasClass('fa-check')){
		isAdd = false;
		obj.removeClass('fa-check').addClass('fa-close');
	}else{
		isAdd = true;
		obj.removeClass('fa-close').addClass('fa-check');
	}

	//1、新增、删除当前对象
	result = addUpdateActGive(isAdd,thisActId,thisfullEname);

	//2、表示有子级 && 是展开状态，则开始批量授权（或取权）子项
	var iObj = obj.parent().parent().find("i");//处理子级
	if(!strUtil.isNull(thisSubCount) && thisSubCount*1>0 && iObj && iObj.hasClass("fa-minus")){
		if(isAdd){
			console.log("同步选中子级勾选状态->");
		}else{
			console.log("同步取消子级勾选状态：");
		}
		userActListObjBody.find("tr[fatherid="+thisActId+"]").each(function () {
			var inputActObj = $(this).find(".fa-2x");
			var childActId = inputActObj.attr("act-id");
			var childfullEname = inputActObj.attr("full-ename");
			result = addUpdateActGive(isAdd,childActId,childfullEname);
			if(isAdd){
				inputActObj.removeClass('fa-close').addClass('fa-check');
			}else{
				inputActObj.removeClass('fa-check').addClass('fa-close');
			}
		});
	}

	//3、非顶级+子级勾选时 情况下 限。
	if(thisFatherId!='0'){
		var fatherCheckObx = userActListObjBody.find("tr[id="+thisFatherId+"]").find(".fa-2x");
		var fatherActId = fatherCheckObx.attr("act-id");
		var fatherfullEname = fatherCheckObx.attr("full-ename");
		if(isAdd){
			//当选中后发现父级未选中，则自动在此选中父级
			if(!fatherCheckObx.hasClass('fa-check')){
				console.log("同步选中父级勾选状态：",thisFatherId+"->"+fatherfullEname);
				result = addUpdateActGive(isAdd,fatherActId,fatherfullEname);
				fatherCheckObx.removeClass('fa-close').addClass('fa-check');
			}
		}else{
			//当全部取消所有兄弟权限后，自动也同步取消父级选中的权限
			var borderCheckedCount = userActListObjBody.find("tr[fatherid="+thisFatherId+"]").find(".fa-check").length;
//                            console.log("同级剩余已勾选个数：",borderCheckedCount);
			if(borderCheckedCount==0){
				isAdd = false;
				console.log("同步取消父级勾选状态：",thisFatherId+"->"+fatherfullEname);
				result = addUpdateActGive(isAdd,fatherActId,fatherfullEname);
				fatherCheckObx.removeClass('fa-check').addClass('fa-close');
			}
		}
	}

}
//提交tab1表单数据
function submitForm1(formId,tabId){
	//校验规则-表单提交时触发
	var validate = $('#'+formId).data('bootstrapValidator').validate();
	if(!validate.isValid()){ //如果校验不通过就返回
	    return;  
	}
	
	var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		var result = submitForm(formId,tabId);
		if(result){
			layer.alert("提交成功！", {closeBtn: 0 });
      		mytools.closeModal("my_modal_add");
      		mytools.closeModal("my_modal_edit");
      		refresh();
		
    		
      		setToken();
    		if(!strUtil.isNull(tabId)){
      			$('.nav-tabs a[href=\"#'+tabId+'\"]').tab('show'); // Select tab by name 
      		}
	  	}
	});
	
 }
//提交表单数据
function submitForm(formId,tabId){
	var result;
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    async:false,
	    dataType:'json',
	    success: function(myData){ 
	     console.log(myData);
	        if(myData.flag=="T"){
	        	result = myData;
	    	}else{
	    		setToken();
	     		layer.alert(myData.msg);
	    	}
	        layer.close(index_load);
	  	},
	     error: function (e) {
		     layer.close(index_load);
     	} 
	});	
	return result;
}

//刷新
function refresh(){
	getTableData();
}
//设置token
function setToken(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
	    	console.log(myData);
			$('.formToken').val(myData);
	  	}
	});	
}


/**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
function setValidate(id){
	$(id).each(function(){
		$(this).bootstrapValidator({
		    feedbackIcons: {
		        valid: 'glyphicon glyphicon-ok',
		        invalid: 'glyphicon glyphicon-remove',
		        validating: 'glyphicon glyphicon-refresh'
		    },/** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
		 	fields:{
		 		/** 可自定义新增验证规则
		    	"uctUser.userEname":{
		    		 validators: {
		    			 regexp: {
		    				 regexp: /^[0-9]+$/,
		                      message: '只能是数字'
		                  }
		              }
		    	}
		    	**/
				}
		});
	});
}


</script>
</section>
<!-- Main end -->   
</div>
<!-- foot start -->
	<#include "/common/plateform/foot.ftl">
<!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>












